<template>
  <div class="common-container">
    <div class="header">
      <div class="header_left">
        <el-popover
          placement="bottom"
          width="460"
          trigger="click"
          popper-class="popover"
          size="small"
          v-model="showPopover"
        >
          <div>
            <el-form
              label-width="70px"
              style="margin: 20px 0"
              class="popover_from"
              :rules="rules"
              :model="searchForm"
              ref="refForm"
            >
              <el-form-item size="small" label="设备编码" prop="imeiList">
                <el-input
                  type="textarea"
                  :rows="8"
                  resize="none"
                  placeholder="多个IMEI号请用“ , ”号隔开"
                  v-model.trim="searchForm.imeiList"
                  :autosize="{ minRows: 4, maxRows: 10 }"
                  style="width: 360px; margin-left: 15px"
                >
                </el-input>
              </el-form-item>
              <el-row>
                <el-col :span="24">
                  <el-form-item size="small" label="租户名称" prop="tenantId">
                    <el-select
                      v-model="searchForm.tenantId"
                      filterable
                      placeholder="租户名称"
                      size="small"
                      style="width: 360px; margin-left: 15px"
                      v-loadMore="loadMore"
                    >
                      <el-option
                        v-for="(item, i) in enterpriseList"
                        :key="i"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                      <div
                        class="div_box"
                        v-loading="loading"
                        :style="loading ? '' : 'display: none;'"
                      ></div>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item size="small" label="产品类型" prop="productId">
                    <el-select
                      v-model="searchForm.productId"
                      placeholder="产品类型"
                      size="small"
                      style="width: 130px; margin-left: 15px"
                      @change="ProductModelPage"
                    >
                      <el-option
                        v-for="item in productList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    size="small"
                    label="产品型号"
                    prop="productModel"
                  >
                    <el-select
                      size="small"
                      style="width: 130px; margin-left: 15px"
                      v-model="searchForm.productModel"
                      placeholder="产品型号"
                    >
                      <el-option
                        v-for="item in classMarkList"
                        :label="item.model"
                        :value="item.model"
                        :key="item.id"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-form-item size="small" label="日期筛选" prop="timeArr">
                <el-date-picker
                  v-model.trim="searchForm.timeArr"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :default-time="['00:00:00', '23:59:59']"
                  :picker-options="pickerOptions"
                  :clearable="false"
                  style="width: 360px"
                >
                </el-date-picker>
              </el-form-item>
            </el-form>
            <div class="footer" style="text-align: right">
              <!-- <el-button size="small" @click="resetClick" class="cancel-button"
                >重 置</el-button
              > -->
              <el-button
                size="small"
                @click="searchClick1"
                class="confirm-button"
                >确 定</el-button
              >
            </div>
          </div>
          <el-button
            size="small"
            slot="reference"
            :class="hasSearch ? 'elhasSearch elhasSearch2' : 'elhasSearch2'"
          >
            高级搜索<i
              class="el-icon-search"
              style="margin-left: 5px; font-size: 12px"
            ></i
          ></el-button>
        </el-popover>
      </div>
      <div class="header_right">
        <el-button
          class="el_button"
          size="small"
          icon="el-icon-upload2"
          @click="onExports"
        >
          导出
        </el-button>
      </div>
    </div>
    <div class="content">
      <el-table
        :data="dataList"
        height="calc(100% - 65px)"
        class="table"
        ref="refTable"
        row-key="id"
        :header-cell-style="headerStyle"
        v-loading="loadingTable"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(47, 51, 73, 0.3)"
      >
        <!-- <el-table-column
          align="center"
          type="selection"
          :reserve-selection="true"
          width="50"
        ></el-table-column> -->
        <el-table-column align="center" label="序号" type="index" width="50">
        </el-table-column>
      
        <el-table-column
          align="center"
          prop="deviceId"
          label="设备ID"
          min-width="270"
          show-overflow-tooltip
        >
        </el-table-column>
          <el-table-column
          align="center"
          prop="imei"
          label="设备编码"
          min-width="180"
          show-overflow-tooltip
        >
        </el-table-column>
         <el-table-column
          align="center"
          prop="messageType"
          label="消息类型"
          min-width="150"
          show-overflow-tooltip
        >
        </el-table-column>
         <el-table-column
          align="center"
          prop="serviceId"
          label="服务ID"
          min-width="150"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="data"
          label="设备原始数据"
          min-width="350"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="reportTime"
          label="上报时间"
          show-overflow-tooltip
          min-width="160"
        >
        </el-table-column>
      </el-table>
      <pagination
        :page.sync="page"
        :limit.sync="limit"
        :total="total"
        @pagination="getDataList"
        class="pagination"
      >
      </pagination>
    </div>
  </div>
</template>

<script>
import {
  reqDeviceOriginalData,
  reqProductList,
} from "@api/api.js";
import tableStyleMixin from "@mixin/table-style";
import Pagination from "@components/Pagination.vue";
import { mapState } from "vuex";
import advanceSearchMixin from "./mixins/advanceSearch.js"; //高级搜索
import loadMore from "@mixin/loadMore";

export default {
  name: "export",
  components: {
    Pagination,
  },
  mixins: [tableStyleMixin, advanceSearchMixin, loadMore],
  data() {
    return {
      showPopover: false, //v-model默认值是false, click激活变成true
      deviceInfo: {}, //设备一条信息
      page: 1,
      limit: 10,
      total: 0,
      dataList: [],
      loadingTable: false,
      loadingSearch: false,
      productList: [],
      batchDataList: [], //批量操作勾选的数据
      hasSearch: false,
    };
  },
  computed: {
    ...mapState(["user"]),
  },
  mounted() {},
  methods: {
    // 获取设备列表
    async getDataList() {
      let { imeiList, productId, tenantId, productModel } =
        this.searchForm;
      if (this.searchForm.timeArr == null) {
        this.searchForm.timeArr = "";
      }
      this.loadingTable = true;
      const res = await reqDeviceOriginalData(this.page, this.limit, {
        imeiList: imeiList != "" ? imeiList.split(",") : [],
        productId,
        tenantId,
        startTime: this.searchForm.timeArr[0] || "",
        endTime: this.searchForm.timeArr[1] || "",
        productModel,
      });
      this.loadingTable = false;
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.hasSearch = productId || tenantId  ? true : false;
      this.dataList = res.data.rows;
      this.total = res.data.total;
      this.exportList = {
        productId,
        imeiList: imeiList != "" ? imeiList.split(",") : [],
        tenantId,
        startTime: this.searchForm.timeArr[0],
        endTime: this.searchForm.timeArr[1],
        productModel,
      };
    },
    getInitDataList() {
      this.page = 1;
      this.limit = 10;
      this.getDataList();
    },
    //   获取产品列表
    async getProductList(flag = false) {
      const res = await reqProductList();
      if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
      this.productList = res.data.rows;
      if (this.productList.length > 0 && flag) {
        this.searchForm.productId = this.productList[0].id;
      }
    },
  },
  created() {},
};
</script>

<style scoped lang="less">
@import url("~@views/style/tablePage.less");

::v-deep .el_button.el-button--small {
  background: #7367f0;
  color: #fff;
  border: none;
}

// 高级搜索
::v-deep .el-button--primary {
  background-color: #7367f0;
  border: 1px solid #7367f0;
  color: #fff;
}

::v-deep .popover_from .el-form-item__label {
  color: @primaryThemeTxtColor2;
  padding: 0px;
}

::v-deep .el-input__inner {
  color: var(--primaryContentTxt, #f1f1f1) !important;
}

::v-deep .el-button--small {
  border: none;
}

// 下拉框加载开始
.div_box {
  height: 276px;
  position: absolute;
  top: -1px;
  left: -1px;
  width: 100%;
  z-index: 9999;
}

/* 定义滚动条样式 */
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  display: block; //显示滚动条
  width: 0px; //定义滚动条宽度
  height: 10px; //定义滚动条高度
  border-radius: 10px; //定义滚动条圆角
}

/*定义滚动条轨道 内阴影+圆角*/
::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  box-shadow: inset 0 0 0px rgba(240, 240, 240, 0.5); //定义轨道阴影
  border-radius: 10px; //定义轨道圆角
  background-color: transparent; //定义轨道颜色
}

/*定义滑块 内阴影+圆角*/
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 10px; //定义滑块圆角
  box-shadow: inset 0 0 0px rgba(240, 240, 240, 0.5); //定义滑块阴影
  background-color: @primaryBgcolor12; //定义滑块颜色
}

// 解决el-table固定列滚动错位问题
::v-deep
  .el-table
  .el-table__fixed-right
  .el-table__fixed-body-wrapper
  .el-table__body {
  padding-bottom: 10px !important;
}

// 解决el-table固定列挡住滚动条问题
::v-deep .el-table__fixed-right {
  height: auto !important;
  bottom: 10px !important; // 这个得自己调试看多少合适
}

// 去掉固定列下方的横线， 样式优化
::v-deep .el-table__fixed-right::before {
  display: none !important;
}

// 解决element-ui 中 table 鼠标悬停时高亮背景颜色的修改，添加fixed后颜色又出现问题  ,鼠标滑过td上作用的样式
::v-deep .el-table tbody tr:hover > td {
  background-color: transparent !important;
}

// 解决element-ui 中 table 鼠标悬停时高亮背景颜色的修改，添加fixed后颜色又出现问题
::v-deep .el-table__body .el-table__row.hover-row td {
  background-color: transparent !important;
}

//右边固定
// 解决element-ui 中 table 鼠标悬停时高亮背景颜色的修改，添加fixed后颜色又出现问题
::v-deep .el-table__fixed-right tbody tr:hover > td {
  background-color: transparent !important;
}
// 日期控件
.el-range-editor.el-input__inner {
  margin-left: 15px;
}

// 日期控件颜色
::v-deep .el-range-editor .el-range-input {
  background: @primaryHeaderBgcolor !important;
  color: @primaryContentTxt;
}
::v-deep .el-textarea__inner {
  background: @primaryHeaderBgcolor;
  border: 1px solid @primaryBorder;
}
</style>
